package com.tanhua.dubbo.api.impl.mongo;


import com.tanhua.domain.mongo.Administration;
import com.tanhua.dubbo.api.mongo.AdministrationApi;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

/**
 * 用户状态管理实现类
 */
@Service
public class AdministrationApiImpl implements AdministrationApi {
    
    
    @Autowired
    private MongoTemplate mongoTemplate;
    
    /**
     * 查询用户冻结状态
     *
     * @param id
     * @return
     */
    @Override
    public Administration queryFreeze(Long id) {
        //通过查询用户id
        Query query = new Query(Criteria.where("userId").is(id));
        //查询
        Administration administration = mongoTemplate.findOne(query, Administration.class);
        if (administration == null) {
            return null;
        }
        //返回冻结范围
        return administration;
    }
    
    /**
     * 保存用户状态
     *
     * @param administration
     */
    @Override
    public void save(Administration administration) {
        mongoTemplate.save(administration);
    }
    
    /**
     * 删除用户状态信息
     *
     * @param id
     */
    @Override
    public void remove(Long id) {
        Query query = new Query(Criteria.where("userId").is(id));
        
        mongoTemplate.remove(query, Administration.class);
    }
}

